package com.jjh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jjh.consts.Result;
import com.jjh.mapper.OrderMapper;
import com.jjh.pojo.Order;
import com.jjh.pojo.User;
import com.jjh.service.OrderService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    private OrderMapper orderMapper;

    /**
     * 条件分页查询
     * @param page
     * @param size
     * @param map
     * @return
     */
    @Override
    public Result page(Integer page, Integer size, Map<String, Object> map) {
        PageHelper.startPage(page,size);
        List<Order> users = getByCondition(map);
        PageInfo<Order> pageInfo = new PageInfo<>(users);
        return Result.ok(pageInfo);
    }

    @Override
    public List<Order> getByCondition(Map<String, Object> conditions) {
        return orderMapper.getByCondition(conditions);
    }

    @Override
    public Result getByOrderId(Long orderId) {

       Order order =  orderMapper.getByOrderId(orderId);
       if(ObjectUtils.isEmpty(order)){
           return Result.error("没有该订单");
       }
       return Result.ok(order);
    }
}
